import java.util.HashMap;
import java.util.Map;

public class Solution {
    public static int edgeScore(int[] edges) {
        Map<Integer,Long> map = new HashMap<>();
        int n=edges.length;
        for (int i = 0; i < n; i++) {
            map.put(edges[i], map.getOrDefault(edges[i],(long)0)+i);
        }
        long max=0;
        int ans=0;
        for (int i = 0; i < n; i++) {
            if(map.containsKey(i) && map.get(i)>max){
                max=map.get(i);
                ans=i;
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        int[] arr={1,0,0,0,0,7,7,5};
        System.out.println(edgeScore(arr));
    }
}
